<%--
  Created by IntelliJ IDEA.
  User: 87070
  Date: 2022/10/27
  Time: 9:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui-v2.7.6/layui/css/layui.css" >
    <script src="${pageContext.request.contextPath}/static/echarts.js"></script>
    <script src="${pageContext.request.contextPath}/static/layui-v2.7.6/layui/layui.js"></script>
</head>
<body>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="returnadd" lay-filter="returnadd" >添加回访</a>
    <%--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>

</script>
<form class="layui-form" action=""  id="saveUserForm" style="display: none"  lay-filter="updateUserFormFilter">
    <input type="hidden" name="id" >

    <form class="layui-form" enctype="multipart/form-data" action="" >


        <div class="layui-form-item">
            <label class="layui-form-label">被回访人</label>
            <div class="layui-input-inline">
                <input type="text" name="username" id="username" onblur="checkUsername(this)"  lay-verify="required"  autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">回访内容</label>
            <div class="layui-input-inline">
                <input type="text" name="recond" id="recond" onblur="checkUsername(this)"  lay-verify="required" placeholder="请输入回访内容" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <input type="text" name="remark" id="remark" onblur="checkUsername(this)"  lay-verify="required" placeholder="请输入备注" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formSaveUser">添加回访</button>
                </div>
            </div>

    </form>
<!-- 为 ECharts 准备一个定义了宽高的 DOM -->

        <%--查询框--%>
            <%--查询条件--%>
            <form class="layui-form" action="">

                <div class="layui-inline">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-inline">
                        <input type="text" name="tel" placeholder="请输入电话号码" autocomplete="off" class="layui-input">
                    </div>
                </div>



                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
            <%--查询条件结束--%>
        <%--存放一个table--%>
            <table class="layui-hide" id="test2" lay-filter = "test2"></table>
    </form>

</div>
<%--存放一个table--%>

<script type="text/javascript">



        layui.use(['table','layer','form','jquery','tree'], function(){
            var tree = layui.tree;
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;
            var $ = layui.jquery;
            var namestatus=true;

            var colordata=[];
            var countdata=[];
            var cicledata=[];



            table.render({
                // element  元素
                elem: '#test2'
                ,page:true
                ,limit:10
                ,limits:[10,20,30]
                ,toolbar: '#toolbarDemo'
                ,url:'${pageContext.request.contextPath}/tSclRecord/tj1' //  表格了里面所需要的数据就是一个list里面有很多的map、对象
                ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                ,totalRow: true
                ,parseData: function (res) {
                    return {
                        "code":res.code,
                        "msg":res.msg,
                        "count": res.data.total,//从返回的json数据中取出总行数
                        "data": res.data.list//返回的json数据有两层，layui不支持多层数据，所以是res.list
                    }
                }
                ,cols: [[
                    // {type: 'checkbox', fixed: 'left'}
                    {type:'numbers',title:'编号'}
                    // field 后面跟的内容  必须跟后台传过来的数据里面的map 的key保持一致
                    ,{field:'username', title: '用户名', sort: true}
                    ,{field:'tel', title: '电话', sort: true}
                    ,{field:'createtime', title: '做题时间', sort: true}
                    ,{field:'ff1', title: '躯体化(F1)', sort: true}
                    ,{field:'ff2', title: '强迫(F2)', sort: true}
                    ,{field:'ff3', title: '人际敏感(F3)', sort: true}
                    ,{field:'ff4', title: '抑郁(F4)', sort: true}
                    ,{field:'ff5', title: '焦虑(F5)', sort: true}
                    ,{field:'ff6', title: '敌对(F6)', sort: true}
                    ,{field:'ff7', title: '恐怖(F7)', sort: true}
                    ,{field:'ff8', title: '偏执(F8)', sort: true}
                    ,{field:'ff9', title: '精神病(F9)', sort: true}
                    ,{field:'ff10', title: '睡眠及饮食(F10)', sort: true}
                    ,{fixed: 'right', title:'操作', minWidth: 125, toolbar: '#barDemo'}
                ]]

            });



            // 查询
            form.on('submit(formDemo)', function(data){
                console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
                console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
                console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
                table.reload('test2', {
                    where: data.field,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });

            //触发单元格工具事件
            //监听行工具事件
            table.on('tool(test2)', function(obj){
                var data = obj.data;
                //console.log(obj)
                if(obj.event === 'returnadd'){
                    $(".pass").css("display","none");
                    document.getElementById("username").onblur = function () {
                    };
                    layer.open({
                        type: 1,
                        area: ['500px', '400px'],
                        offset: '100px',
                        content:$("#saveUserForm"),
                        cancel: function (index, layero) {

                            layer.close(index);
                            $("#saveUserForm").hide();
                            return false;
                        }
                    });
                    form.val('')

                    form.val('updateUserFormFilter',data);
                    $("#demo1").prop("src",data.imgpath);
                }
            });

            //提交表单
            // Layui提交表单 监听提交  data代表的是form表单里面的所有的内容
            form.on('submit(formSaveUser)', function(data){
                var username=$("#username").val();
                var recond=$("#recond").val();
                var remark=$("#remark").val();
                var params = {};
                params.username=username;
                params.recond=recond;
                params.remark=remark;
                if(namestatus){
                    $.ajax({
                        url:"${pageContext.request.contextPath}/tTestRecondScl/addHf",
                        type:"post",
                        dataType:"JSON",
                        data:params,//表单里所有数据
                        success:function (ret){
                            alert(ret.data);
                            if (ret.data == true){
                                layer.alert("添加成功");
                                //关闭所有弹框
                                layer.closeAll();
                                //隐藏表单
                                $("#formSaveUser").hide();
                                //刷新页面
                                table.reload('test2');
                                $("#saveUserForm").hide();
                            }else {
                                layer.alert("添加失败，该用户已添加回访")
                                window.location="${pageContext.request.contextPath}/tTestRecondScl/tiaoZhuan";
                            }
                        }
                    })
                }
                return false;
            });


    })


</script>
</body>


</html>
